<?php

namespace app\api\controller;

use support\Log;
use support\Request;
use app\controller\BaseController;
use app\model\Spot;
use support\exception\BusinessException;
use think\facade\Db;

class IndexController extends BaseController
{
    public function test1()
    {
        self::consoleln("this is api test1 ");
        $model = Spot::where(["valid" => 1])->limit(10)->select();
        $request = request();
        $app = $request->app;
        // sleep(1);
        var_dump("test1==");
        var_dump($app);
        return json(["count" => count($model)]);
        /*print_r(config("thinkorm"));

        $list = Db::table("rh_spot")->where("id", ">", 0)->find();
        print_r($list);
        return json($list);*/
    }


    public function test2(Request $request)
    {
        self::consoleln("this is api test2 ");
        Log::debug("开始查询数据库");
        $model = Spot::where(["valid" => 1])->limit(10)->select();
        Log::debug("开始查询第2条数据库");
        $model = Spot::where(["valid" => 0])->limit(10)->select();
        Log::debug("开始接收参数");
        $id = input("id");
        if ($id) {
            $this->success(["type" => "成功"], "成功了");
        }
        $this->error(999, "id不能为空", ["type" => "失败"]);
    }

    protected function chackInpout($input)
    {
        var_dump(13);
        throw new BusinessException(json_encode(["a" => "b"]), 3000);
    }
}